package com.certification.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.common.utils.Constant;
import com.certification.service.CorrectImproveService;
import com.certification.service.SysUserRoleService;
import com.certification.vo.CorrectImproveAdminVO;
import com.certification.vo.PageVO;
import com.certification.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author copa
 * @createDate 2022-03-30 22:17
 * @function
 */
@RestController
@Api(tags = {"流程：整改提高"})
public class CorrectImproveController extends AbstractController {

    @Resource
    private CorrectImproveService correctImproveService;

    @Resource
    private SysUserRoleService sysUserRoleService;

    @GetMapping("admin/improvePage/{certId}")
    @ApiOperation(value = "查看整改提高分页(认证专家)")
    public ResponseMessage<IPage<CorrectImproveAdminVO>> getImproveDetailAdminPage(@PathVariable Integer certId, PageVO pageVO) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return correctImproveService.getImproveDetailAdminPage(certId, pageVO);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @GetMapping("admin/improve/{certId}/{proId}")
    @ApiOperation(value = "查看整改提高(认证专家)")
    public ResponseMessage<CorrectImproveAdminVO> getImproveDetailAdmin(@PathVariable Integer certId,
                                                                        @PathVariable Integer proId) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return correctImproveService.getImproveDetailAdmin(certId, proId);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @PutMapping("admin/improve")
    @ApiOperation(value = "判定认证是否通过：第五阶段")
    public ResponseMessage<String> putImproveAdmin(@RequestParam @ApiParam("认证id") Integer certId,
                                     @RequestParam @ApiParam("同意-1 驳回-2") Integer status,
                                     @RequestParam(required = false) @ApiParam("驳回和同意写理由") String remark) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return correctImproveService.putImproveAdmin(certId, status, remark);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }


}
